﻿using Ags.MonsterTools.Common;
using MahApps.Metro.Controls;
using System;
using System.ComponentModel;
using System.Media;
using System.Windows;
using System.Windows.Resources;

namespace Ags.MonsterTools
{
    /// <summary>
    /// Interaction logic for AboutWindow.xaml
    /// </summary>
    public partial class AboutWindow : MetroWindow, IView
    {
        private SoundPlayer _sp;

        public AboutWindow(AboutWindowViewModel viewModel)
        {
            this.DataContext = viewModel;
            InitializeComponent();
        }

        private void LoadPlayer()
        {
            var uri = new Uri(@"pack://application:,,,/MonsterTools;component/Media/Theme.wav");
            StreamResourceInfo sri = Application.GetResourceStream(uri);
            if (sri != null)
            {
                _sp = new SoundPlayer(sri.Stream);
                _sp.LoadCompleted += _sp_LoadCompleted;
                _sp.LoadAsync();
            }
        }

        void _sp_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            _sp.Play();
        }

        private void AboutWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            LoadPlayer();
        }

        public string HeaderContent
        {
            get { return "About"; }
        }

        public void Dispose()
        {
            _sp.Stop();
            _sp.Dispose();
            _sp = null;
        }
    }
}
